#ifndef _MIX_THREAD_RWLOCK_H_
#define _MIX_HTREAD_RWLOCK_H_

namespace mix
{

class RWLock
{
public:
    RWLock();
    ~RWLock();

    void rdLock();
    bool tryRDLock();
    bool tryRDLock( long usec);

    void wrLock();
    bool tryWRLock();
    bool tryWRLock( long usec);

    void unlock();

    void* getNative();

    class RDGuard
    {
        RWLock& _locker;
    public:
        RDGuard( RWLock& locker) : _locker( locker) {
            _locker.rdLock();
        }
        
        ~RDGuard() {
            _locker.unlock();
        }
    };

    class WRGuard
    {
        RWLock _locker;
    public:
        WRGuard( RWLock& locker) : _locker( locker) {
            _locker.wrLock();
        }
        
        ~WRGuard() {
            _locker.unlock();
        }
    };

private:
    void* _impl;

};


}   // namespace mix

#endif
